﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KabiManagementWeb.Models;
using System.Globalization;
namespace KabiManagementWeb.Controllers
{
    public class StatisticsController : Controller
    {
        private StatisticsFacade facade = new StatisticsFacade(DBUtils.DBType.Local);
        private KBManagementDataContext context = DBUtils.GetContext(DBUtils.DBType.Local);
        //
        // GET: /Statistics/
        private void GetViewIndexData()
        {

            ViewData["Time"] = new SelectList(new List<SelectListItem> { 
                new SelectListItem { Text = "Trong ngày", Value = "day" },
                new SelectListItem { Text = "Trong Tuần", Value = "week" } ,
                new SelectListItem { Text = "Trong Tháng", Value = "month" } ,
                new SelectListItem { Text = "Trong Năm", Value = "year" } }, "Value", "Text");
            if (context.funds_generals.ToList().Count > 0)
                ViewData["Funds"] = context.funds_generals.ToList()[0].balance.Value;
        }
        public ActionResult Index()
        {
            var sta = facade.GetStatistics(StatisticsTime.day);
            GetViewIndexData();
            return View(sta);
        }
        [HttpPost]
        public ActionResult Index(string time)
        {
            var sta = new Statistic();
            if (time == "day")
            {
                sta = facade.GetStatistics(StatisticsTime.day);
            }

            if (time == "week")
            {
                sta = facade.GetStatistics(StatisticsTime.week);
            }
            if (time == "month")
            {
                sta = facade.GetStatistics(StatisticsTime.month);
            }
            if (time == "year")
            {
                sta = facade.GetStatistics(StatisticsTime.year);
            }
            GetViewIndexData();
            return View(sta);

        }
        [HttpPost]
        public ActionResult ViewDate(string date1)
        {
            var sta = new Statistic();
            DateTime d = Convert.ToDateTime(date1);
            facade.ViewDayStatistics(sta, d);
            GetViewIndexData();
            return View(sta);

        }
        public ActionResult RewardPenalty()
        {
            return View();
        }
     
    }
}
